home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / src / info.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.2 KB  |  256 lines

  1. /* Panel managing.
  2.    Copyright (C) 1994, 1995 Janne Kukonlehto
  3.    Copyright (C) 1995 Miguel de Icaza
  4.    
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2 of the License, or
  8.    (at your option) any later version.
  9.    
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <config.h>
  20. #include "tty.h"
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <sys/param.h>
  24. #include <malloc.h>
  25. #include "mad.h"
  26. #include "util.h"        /* statfs calls */
  27. #include "mouse.h"        /* Gpm_Event */
  28. #include "color.h"
  29. #include "dlg.h"
  30. #include "info.h"
  31. #include "dir.h"        /* required by panel */
  32. #include "panel.h"        /* for the panel structure */
  33. #include "main.h"        /* opanel, cpanel definitions */
  34. #include "win.h"        /* print_bytesize */
  35. #include "layout.h"
  36.  
  37. /* Have we called the init_my_statfs routine? */
  38. static int initialized;
  39. struct my_statfs myfs_stats;
  40.  
  41. static int info_event (Gpm_Event *event, WInfo *info)
  42. {
  43.     return 0;
  44. }
  45.  
  46. static void info_box (Dlg_head *h, WInfo *info)
  47. {
  48.     standend ();
  49.     if (hascolors)
  50.     attrset (NORMAL_COLOR);
  51.     widget_erase (&info->widget);
  52.     draw_double_box (h, info->widget.y,  info->widget.x,
  53.                  info->widget.lines, info->widget.cols);
  54. }
  55.  
  56. #ifndef VERSION
  57. #   define VERSION "undefined"
  58. #endif
  59.  
  60. void info_show_info (WInfo *info)
  61. {
  62.     struct stat buf;
  63.  
  64. #ifndef HAVE_X
  65.     if (!is_idle ())
  66.     return;
  67.  
  68.     info_box (info->widget.parent, info);
  69.     set_attr (0, 1);
  70.     widget_move (&info->widget, 1, 3);
  71.     printw ("Midnight Commander %s", VERSION);
  72.     set_attr (0, 0);
  73.     widget_move (&info->widget, 2, 1);
  74.     hline (ACS_HLINE|NORMAL_COLOR, info->widget.x-2);
  75. #endif
  76.     if (get_current_type () != view_listing)
  77.     return;
  78.  
  79.     if (!info->ready)
  80.     return;
  81.     
  82.     my_statfs (&myfs_stats, cpanel->cwd);
  83.     buf = cpanel->dir.list [cpanel->selected].buf;
  84. #ifndef HAVE_X
  85.     /* Print only lines which fit */
  86.     switch (info->widget.y-2){
  87.     /* Note: all cases are fall-throughs */
  88.     
  89.     default:
  90.  
  91.     case 16:
  92.     widget_move (&info->widget, 16, 3);
  93.     if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
  94.         printw ("Free nodes %d (%d%%) of %d",
  95.             myfs_stats.nfree,
  96.             myfs_stats.total
  97.             ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
  98.             myfs_stats.nodes);
  99.     else
  100.         addstr ("No node information");
  101.     
  102.     case 15:
  103.     widget_move (&info->widget, 15, 3);
  104.     if (myfs_stats.avail > 0 || myfs_stats.total > 0){
  105.         addstr ("Free space ");
  106.         print_bytesize (myfs_stats.avail, 1);
  107.         printw (" (%d%%) of ", myfs_stats.total
  108.             ? 100 * myfs_stats.avail / myfs_stats.total : 0);
  109.         print_bytesize (myfs_stats.total, 1);
  110.     } else
  111.         addstr ("No space information");
  112.  
  113.     case 14:
  114.     widget_move (&info->widget, 14, 3);
  115.     printw ("Type:      %s ", myfs_stats.typename ? myfs_stats.typename : "non-local vfs");
  116.     if (myfs_stats.type != 0xffff && myfs_stats.type != 0xffffffff)
  117.         printw (" (%Xh)", myfs_stats.type);
  118.  
  119.     case 13:
  120.     widget_move (&info->widget, 13, 3);
  121.     printw ("Device:    %s",
  122.         name_trunc (myfs_stats.device, info->widget.cols - 15));
  123.     case 12:
  124.     widget_move (&info->widget, 12, 3);
  125.     printw ("Filesystem: %s",
  126.         name_trunc (myfs_stats.mpoint, info->widget.cols - 15));
  127.  
  128.     case 11:
  129.     widget_move (&info->widget, 11, 3);
  130.     printw ("Accessed:  %s", file_date (buf.st_atime));
  131.     
  132.     case 10:
  133.     widget_move (&info->widget, 10, 3);
  134.     printw ("Modified:  %s", file_date (buf.st_mtime));
  135.     
  136.     case 9:
  137.     widget_move (&info->widget, 9, 3);
  138.     printw ("Created:   %s", file_date (buf.st_ctime));
  139.  
  140.     case 8:
  141.     widget_move (&info->widget, 8, 3);
  142. #if 0
  143. #ifdef HAVE_ST_RDEV
  144.     if (buf.st_rdev)
  145.         printw ("Inode dev: major: %d, minor: %d",
  146.             buf.st_rdev >> 8, buf.st_rdev & 0xff);
  147.     else
  148. #endif
  149. #endif
  150.     {
  151.         printw ("Size:      ");
  152.         print_bytesize (buf.st_size, 0);
  153. #ifdef HAVE_ST_BLOCKS
  154.         printw (" (%d blocks)", buf.st_blocks);
  155. #endif
  156.     }
  157.     
  158.     case 7:
  159.     widget_move (&info->widget, 7, 3);
  160.     printw ("Owner:     %s/%s", get_owner (buf.st_uid),
  161.         get_group (buf.st_gid));
  162.     
  163.     case 6:
  164.     widget_move (&info->widget, 6, 3);
  165.     printw ("Links:     %d", buf.st_nlink);
  166.     
  167.     case 5:
  168.     widget_move (&info->widget, 5, 3);
  169.     printw ("Mode:      %s (%o)",
  170.         string_perm (buf.st_mode), buf.st_mode & 07777);
  171.     
  172.     case 4:
  173.     widget_move (&info->widget, 4, 3);
  174.     printw ("Location:  %Xh:%Xh", buf.st_dev, buf.st_ino);
  175.     
  176.     case 3:
  177.     widget_move (&info->widget, 3, 2);
  178.     printw ("File:       %s",
  179.         name_trunc (cpanel->dir.list [cpanel->selected].fname,
  180.                 info->widget.cols - 15));
  181.     case 2:
  182.     case 1:
  183.     case 0:
  184.     ;
  185.     } /* switch */
  186. #else /* HAVE_X */
  187.     x_show_info (info, &myfs_stats, &buf);
  188. #endif
  189. }
  190.  
  191. static void info_hook (void *data)
  192. {
  193.     WInfo *info = (WInfo *) data;
  194.     Widget *other_widget;
  195.     
  196.     other_widget = get_panel_widget (get_current_index ());
  197.     if (!other_widget)
  198.     return;
  199.     if (dlg_overlap (&info->widget, other_widget))
  200.     return;
  201.     
  202.     info->ready = 1;
  203.     info_show_info (info);
  204. }
  205.  
  206. static void info_destroy (WInfo *info)
  207. {
  208.     delete_hook (&select_file_hook, info_hook);
  209. }
  210.  
  211. static int info_callback (Dlg_head *h, WInfo *info, int msg, int par)
  212. {
  213.     switch (msg){
  214.  
  215.     case WIDGET_INIT:
  216.     add_hook (&select_file_hook, info_hook, info);
  217.     info->ready = 0;
  218. #ifdef HAVE_X
  219.     x_create_info (h, h->wdata, info);
  220. #endif
  221.     break;
  222.  
  223. #ifndef HAVE_X          
  224.     case WIDGET_DRAW:
  225.     info_hook (info);
  226.     info_show_info (info);
  227.     return 1;
  228. #endif    
  229.  
  230.     case WIDGET_FOCUS:
  231.     return 0;
  232.     }
  233.     return default_proc (h, msg, par);
  234. }
  235.                
  236. WInfo *info_new ()
  237. {
  238.     WInfo *info = xmalloc (sizeof (WInfo), "panel_info");
  239.  
  240.     init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
  241.          info_callback, (destroy_fn) info_destroy,
  242.          (mouse_h) info_event);
  243.  
  244.     /* We do not want the cursor */
  245.     widget_want_cursor (info->widget, 0);
  246.  
  247.     my_statfs (&myfs_stats, cpanel->cwd);
  248.  
  249.     if (!initialized){
  250.     initialized = 1;
  251.     init_my_statfs ();
  252.     }
  253.     return info;
  254. }
  255.  
  256.